

import tkinter as tk
from tkinter import scrolledtext
import random

def send_message(event=None):
    message = entry.get()
    if message:
        chat_history.config(state=tk.NORMAL)
        chat_history.insert(tk.END, "你: " + message + "\n")
        
        # 随机选择电脑的回答
        responses = ["好的，我明白了。", "请告诉我更多。", " interesting!"]
        response = random.choice(responses)
        chat_history.insert(tk.END, "电脑: " + response + "\n")
        
        chat_history.config(state=tk.DISABLED)
        entry.delete(0, tk.END)

root = tk.Tk()
root.title("仿微信对话窗口")

frame = tk.Frame(root)
frame.pack(padx=10, pady=10)

# 设置较大的字体
large_font = ('Arial', 14)

chat_history = scrolledtext.ScrolledText(frame, width=50, height=20, state=tk.DISABLED, font=large_font)
chat_history.pack(side=tk.TOP, padx=10, pady=10)

entry = tk.Entry(frame, width=40, font=large_font)
entry.pack(side=tk.LEFT, padx=(10, 0), pady=10)
entry.bind('<Return>', send_message)  # 绑定回车键事件

send_button = tk.Button(frame, text="发送", command=send_message, font=large_font)
send_button.pack(side=tk.RIGHT, padx=(0, 10), pady=10)

root.mainloop()
